#pragma once

#include "WindowedUI.h"

#include <GdiPlus.h>
#include <string>




// CSkinButton

class CSkinButton;
class ISkinButtonEvent;

class ISkinButtonEvent
{
public:
	virtual void OnClick(CSkinButton* pEventSource) = 0;
	virtual void OnDClick(CSkinButton* pEventSource) = 0;
};

class UIELEMENT_API CSkinButton : public CButton, public CWindowedUI
{
	DECLARE_DYNAMIC(CSkinButton)

public:
	CSkinButton(bool bOwnerDraw = true);
	virtual ~CSkinButton();

public:
	void SetEventHandler(ISkinButtonEvent* pEventHandler);

protected:
	virtual void PreSubclassWindow();
	virtual void DrawItem(LPDRAWITEMSTRUCT /*lpDrawItemStruct*/);

protected:
	DECLARE_MESSAGE_MAP()

protected:
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnDestroy();
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg virtual LRESULT OnMouseLeave(WPARAM wparam, LPARAM lparam);
	afx_msg virtual LRESULT OnMouseHover(WPARAM wparam, LPARAM lparam);

protected:
	typedef enum enmButtonState
	{
		enmButtonState_Normal   = 0,
		enmButtonState_Hover    = 1,
		enmButtonState_Down     = 2,
		enmButtonState_Disabled = 3,

		enmButtonState_Checked  = 4,
	} ButtonMouseState;

protected:
	virtual void DrawState(Gdiplus::Graphics* pGraphics,
		ButtonMouseState eState, CRect rcItem, int nItemState);

	virtual void DrawText(Gdiplus::Graphics* pGraphics, const CRect& rcText);

	virtual void ChangeState(ButtonMouseState eState);

protected:
	BOOL m_bTracking;
	bool m_bOwnerDraw;

	ButtonMouseState m_eState;


	std::wstring   m_strFontName;
	Gdiplus::Color m_crFontColor;
	INT            m_nFontStyle;
	Gdiplus::REAL  m_fFontSize;
	Gdiplus::StringFormat m_format;

	ISkinButtonEvent* m_pEventHandler;
	

protected:
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnBnClicked();
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
public:
	afx_msg void OnEnable(BOOL bEnable);
};

